/*
 * Vault class based on AWS SDK code samples
 * Supports create, describe, list and delete operations
 * 
 * Distributed under Apache 2.0 license
 * Author: David Mail, email: david.mail37(at)gmail(dot)com
 * October 7 2012
 */

package com.pixamba.aws.glacier;

import com.amazonaws.services.glacier.model.CreateVaultRequest;
import com.amazonaws.services.glacier.model.CreateVaultResult;
import com.amazonaws.services.glacier.model.DeleteVaultRequest;
import com.amazonaws.services.glacier.model.DescribeVaultOutput;
import com.amazonaws.services.glacier.model.DescribeVaultRequest;
import com.amazonaws.services.glacier.model.DescribeVaultResult;
import com.amazonaws.services.glacier.model.ListVaultsRequest;
import com.amazonaws.services.glacier.model.ListVaultsResult;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author david
 */
public class AwsGlacierVault extends AwsGlacier {
    
    public AwsGlacierVault( String configFile) throws IOException {
        super( configFile);
    }
   
    public String create( String name){
        CreateVaultRequest createVaultRequest = new CreateVaultRequest().withVaultName( name);
        CreateVaultResult createVaultResult = this.client.createVault( createVaultRequest);
        return createVaultResult.getLocation();
    }
    
    public String describe( String name){
        DescribeVaultRequest describeVaultRequest = new DescribeVaultRequest().withVaultName(name);
        DescribeVaultResult describeVaultResult  = this.client.describeVault(describeVaultRequest);
        return
                "CreationDate: " + describeVaultResult.getCreationDate() +
                "\nLastInventoryDate: " + describeVaultResult.getLastInventoryDate() +
                "\nNumberOfArchives: " + describeVaultResult.getNumberOfArchives() + 
                "\nSizeInBytes: " + describeVaultResult.getSizeInBytes() + 
                "\nVaultARN: " + describeVaultResult.getVaultARN() + 
                "\nVaultName: " + describeVaultResult.getVaultName();        
    }
    
    public ArrayList<String> list(){
        ListVaultsRequest listVaultsRequest = new ListVaultsRequest();
        ListVaultsResult listVaultsResult = client.listVaults(listVaultsRequest);

        List<DescribeVaultOutput> vaultList = listVaultsResult.getVaultList();
        ArrayList<String> strings = new ArrayList<String>( 5);
        for( DescribeVaultOutput vault : vaultList) {
            strings.add(
                    "\nCreationDate: " + vault.getCreationDate() +
                    "\nLastInventoryDate: " + vault.getLastInventoryDate() +
                    "\nNumberOfArchives: " + vault.getNumberOfArchives() + 
                    "\nSizeInBytes: " + vault.getSizeInBytes() + 
                    "\nVaultARN: " + vault.getVaultARN() + 
                    "\nVaultName: " + vault.getVaultName()); 
        }
        return strings;
    }
    
    public void delete( String name){
        DeleteVaultRequest request = new DeleteVaultRequest().withVaultName(name);
        this.client.deleteVault(request);
    }
    
}
